package cn.da.shuai.cool.finance.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.finance.model.CoolTaxDeclaration;
import cn.da.shuai.cool.finance.model.vo.SearchTaxDeclarationVo;
import cn.da.shuai.cool.finance.service.ICoolTaxDeclarationService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 税务申报表 前端控制器
 * </p>
 *
 * @author 大帅哥
 * @since 2023-05-01
 */
@Tag(name = "税务申报管理")
@RestController
@RequestMapping("/finance/tax-declaration")
@RequiredArgsConstructor
public class CoolTaxDeclarationController {

    private final ICoolTaxDeclarationService taxDeclarationService;

    @Operation(summary = "分页查询税务申报")
    @PostMapping("/page")
    public R<Page<CoolTaxDeclaration>> page(@RequestBody SearchTaxDeclarationVo vo) {
        LambdaQueryWrapper<CoolTaxDeclaration> wrapper = new LambdaQueryWrapper<CoolTaxDeclaration>()
                .eq(vo.getTaxType() != null, CoolTaxDeclaration::getTaxType, vo.getTaxType())
                .eq(vo.getDeclarationPeriod() != null, CoolTaxDeclaration::getDeclarationPeriod, vo.getDeclarationPeriod())
                .eq(vo.getStatus() != null, CoolTaxDeclaration::getStatus, vo.getStatus())
                .orderByDesc(CoolTaxDeclaration::getDeclarationPeriod);

        return R.ok(taxDeclarationService.page(new Page<>(vo.getPageNum(), vo.getPageSize()), wrapper));
    }

    @Operation(summary = "获取税务申报详情")
    @GetMapping("/{id}")
    public R<CoolTaxDeclaration> getById(@PathVariable Long id) {
        return R.ok(taxDeclarationService.getById(id));
    }

    @Operation(summary = "新增税务申报")
    @PostMapping
    public R<Boolean> add(@RequestBody CoolTaxDeclaration taxDeclaration) {
        return R.ok(taxDeclarationService.save(taxDeclaration));
    }

    @Operation(summary = "修改税务申报")
    @PutMapping
    public R<Boolean> update(@RequestBody CoolTaxDeclaration taxDeclaration) {
        return R.ok(taxDeclarationService.updateById(taxDeclaration));
    }

    @Operation(summary = "删除税务申报")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return R.ok(taxDeclarationService.removeById(id));
    }
}